<template>
    <view class="buyToolbar" :class="{'show':alonePrice > 0 }">

        <view class="box" v-if="isGroup == 1">

            <view class="alone inSide" v-if="goodsGroupPurchaseId">

                <!-- <view class="comm fr bugGroup " @click="goBuy('group')">
                    <view class="num">
                        <text class="" v-if="groupPrice"><text class="min">￥</text><text class="b">{{groupPrice || 0}}</text></text>
                        <text class="tag">限时购</text>
                    </view>
                    <view class="text">点击参与拼单</view>
                </view> -->

                <view class="commonFoot">
                    <view class="foot-btn-box fixed">
                        <view class="foot-btn transBg6" @click="goBuy('group')">
                           <text class="mr5" v-if="groupPrice"><text class="min">￥</text><text class="b">{{groupPrice || 0}}</text></text>
                            
                            <text class="">参与拼团</text>
                            <text class="tag">限时购</text>
                        </view>

                    </view>
                </view>

            </view>

            <view class="inSide" v-else>

                <view class="comm fl bugCar" @click="goBuy('single')">
                    <view class="num">
                        <text class="" v-if="groupPrice"><text class="min">￥</text><text class="b">{{alonePrice || 0}}</text></text>
                        <text v-else class="tip">急速发货 </text>
                    </view>
                    <view class="text">单独购买</view>
                </view>

                <view class="comm fr bugGroup " @click="goBuy('group')">
                    <view class="num">
                        <text class="" v-if="groupPrice"><text class="min">￥</text><text class="b">{{groupPrice || 0}}</text></text>
                        <text class="tag">限时购</text>
                    </view>
                    <view class="text">发起拼单</view>
                </view>

            </view>

        </view>
        <view class="box alone" v-else>

            <view class="commonFoot">
                <view class="foot-btn-box fixed">
                    <view class="foot-btn" @click="goBuy('single')">
                        <text class="min">￥</text><text class="b">{{alonePrice || 0}}</text> <text class="ml10">立即下单</text>
                    </view>

                </view>
            </view>

            <!-- <view class="comm fl bugCar" @click="goBuy('single')">
                <view class="text"> <text class="min">￥</text><text class="b">{{alonePrice || 0}}</text> <text class="ml20">立即下单</text> </view>
            </view> -->

        </view>
    </view>

    </view>
</template>

<script>

const app = getApp();
export default {
    props: ['hasBeforSub', 'limit', 'goodsId', 'isGroup', 'goodsGroupPurchaseId'],
    components: {},
    data () {
        return {
            userId: app.globalData.userId,
            selectAutoList: {}, //选中的分类 分类数字作为key sonArr为第三级
            showDetail: false, //展示选中的详情
            // groupPrice: { cateNum: 0, price: 0 }, //计算
            productPrice: {},
            //弹出授权框
            showAuthorize: false,
            groupPrice: 0,
            alonePrice: 0,
        }
    },
    computed: {
        selectProduct () {

            return this.$store.getters.selectProduct
        }
    },
    watch: {
        selectProduct: {
            immediate: true,
            deep: true,
            handler (current) {

                // console.log('购物变没变', current)

                this.countPriceFunc(current)
            }
        }
    },
    mounted () {

    },
    methods: {

        countPriceFunc (current) {

            let groupPrice = 0;

            let alonePrice = 0

            Object.keys(current).map(key => {

                if (key == this.goodsId) {

                    let item = current[key]

                    let minTotal = Number((item.salePricePt * item.count).toFixed(2))


                    groupPrice += minTotal

                    alonePrice += Number((item.salePrice * item.count).toFixed(2))


                }



            })

            console.log('购物变没变', current)



            this.alonePrice = alonePrice

            this.groupPrice = groupPrice

            // this.isChange = true 

            // setTimeout(()=>{

            //     this.isChange = false

            // },200)


        },
        goBuy (type) {

            // this.$goNext('/pages/supermarket/order/index?supermarketId='+this.supermarketId)

            if (this.alonePrice == 0) {

                return
            }



            if (this.hasBeforSub) {

                this.$emit('beforSubmitFunc', type)

            }
            else {
                this.$goNext('/pages/supermarket/order/index?supermarketId=' + app.globalData.supermarketId)
            }





        },
        emptyEvent () {
            return false;
        },

    }
}
</script>

<style scoped lang="scss">
/* //底部购物车 */

.buyToolbar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 111;
    // background: #fff;
    height: 120rpx;
    box-sizing: border-box;
    transform: translateY(100%);
    transition: all 0.2s;
    &.show {
        transform: translateY(0%);
    }
}
.buyToolbar .box {
    box-sizing: border-box;
    position: absolute;
    left: 0;
    bottom: 0rpx;
    z-index: 14;
    height: 120rpx;
    background: #fff;
    // box-shadow: 0 0 10px #eaeaea;
    // border-top: 1px solid #d1d1d1;
    width: 100%;
    // border-radius: 16rpx;
    font-size: 32rpx;
    text-align: center;
    .inSide {
        width: 100%;
        height: 100%;
    }

    .comm {
        padding: 10rpx 0;
    }

    .num {
        text-align: center;
        line-height: 50rpx;
        height: 50rpx;
        font-size: 38rpx;
    }
    .bugCar {
        width: 32%;
        height: 100%;
        position: relative;
        background: #fae5e2;
        color: #dd262d;
    }
    .tag {
        display: inline-block;
        padding: 6rpx 12rpx;
        border-radius: 20rpx 6rpx 20rpx 6rpx;
        background: #fff;
        color: #dd262d;
        font-size: 20rpx;
        line-height: 1.1em;
        margin-left: 10rpx;
        position: relative;
        top: -10rpx;
    }
    .min {
        font-size: 24rpx;
    }

    .bugGroup {
        width: 68%;
        height: 100%;
        background: #ff2d46;
        color: #ffff;
    }
    .tip {
        font-size: 22rpx;
    }
}

.commonFoot .foot-btn-box {
    height: 80px;
}
</style>
